﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NLite.Test.IoC.Addins.Components
{
    [Component]
    public class AddInManager:IAddInManager
    {
        [InjectMany]
        IEnumerable<Lazy<IAddIn, IAddInMetadata>> AddIns { get; set; }

        public void Start()
        {
            foreach (var item in AddIns)
            {
                Console.WriteLine(string.Format("Name={0},Author={1},Url={2},Version={3}", item.Metadata.Name,item.Metadata.Author,item.Metadata.Url,item.Metadata.Version));
                item.Value.Start();
            }
        }

        public void Stop()
        {
        }
    }


    [Component]
    public class ArrayMetadataAddInManager : IAddInManager
    {
        [InjectMany]
        Lazy<IAddIn, IAddInMetadata>[] AddIns { get; set; }

        public void Start()
        {
            foreach (var item in AddIns)
            {
                Console.WriteLine(string.Format("Name={0},Author={1},Url={2},Version={3}", item.Metadata.Name, item.Metadata.Author, item.Metadata.Url, item.Metadata.Version));
                item.Value.Start();
            }
        }

        public void Stop()
        {
        }
    }

    [Component]
    public class ArrayAddInManager : IAddInManager
    {
        [InjectMany]
        IAddIn[] AddIns { get; set; }

        public void Start()
        {
            foreach (var item in AddIns)
            {
                item.Start();
            }
        }

        public void Stop()
        {
        }
    }

    [Component]
    public class ArrayConstructureAddInManager : IAddInManager
    {
        private IAddIn[] AddIns;

        public ArrayConstructureAddInManager([InjectMany] IAddIn[] addins)
        {
            AddIns = addins;
        }

        public void Start()
        {
            foreach (var item in AddIns)
            {
                item.Start();
            }
        }

        public void Stop()
        {
        }
    }


    [Component]
    public class ArrayMethodAddInManager : IAddInManager
    {
        private IAddIn[] AddIns;

        [Inject]
        public void SetAddIns([InjectMany] IAddIn[] addins)
        {
            AddIns = addins;
        }

        public void Start()
        {
            foreach (var item in AddIns)
            {
                item.Start();
            }
        }

        public void Stop()
        {
        }
    }
}
